const Controller = require("egg").Controller;
class RoleController extends Controller {
    async index() {
        const { model } = this.ctx;
        const query = {};
        const reslut = await model.Role.findAll();
        this.ctx.body = {
            code: 200,
            msg: '',
            data: reslut

        };
    }
    async create() {
        const { model } = this.ctx;
        const { rol_name } = this.ctx.request.body;
        const role = await model.Role.create({ rol_name });
        this.ctx.body = role;
    }
    async update() {
        const { model } = this.ctx;
        const { id } = this.ctx.request.body;
        const role = await model.Role.update({
            where: {
                id: id
            },
            rol_name: 'aa'
        });
        this.ctx.body = role;
    }
    async destroy() {
        const { model } = this.ctx;
        const { id } = this.ctx.request.body;
        const role = await model.Role.findByPk(id);
        if (!role) {
            ctx.status = 404;
            return;
        }
        await model.Role.destroy();
        this.ctx.body = {
            code: 200,
            mesg: "删除成功"
        };
    }
}

module.exports = RoleController;